class DefendersController < ApplicationController
  def index
    @attack = Attack.find(params[:attack_id])
    @defenders = @attack.defenders

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @defenders }
    end
  end

  def show
    @attack = Attack.find(params[:attack_id])
    @defender = Defender.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @defender }
    end
  end

  def new
    @attack = Attack.find(params[:attack_id])
    @defender = @attack.defender.build

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @defender }
    end
  end

  def edit
    @attack = Attack.find(params[:attack_id])
    @defender = Defender.find(params[:id])
  end

  def create
    @attack = Attack.find(params[:attack_id])
    @defender = @attack.defender.build(params[:defender])

    respond_to do |format|
      if @defender.save
        flash[:notice] = 'Defender was successfully created.'
        format.html { redirect_to attack_defender_path(@attack, @defender) }
        format.xml  { render :xml => @defender, :status => :created, :location => @defender }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @defender.errors, :status => :unprocessable_entity }
      end
    end
  end

  def update
    @attack = Attack.find(params[:attack_id])
    @defender = Defender.find(params[:id])

    respond_to do |format|
      if @defender.update_attributes(params[:defender])
        flash[:notice] = 'Defender was successfully updated.'
        format.html { redirect_to attack_defender_path(@attack, @defender) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @defender.errors, :status => :unprocessable_entity }
      end
    end
  end

  def destroy
    @attack = Attack.find(params[:attack_id])
    @defender = Defender.find(params[:id])
    @defender.destroy

    respond_to do |format|
      format.html { redirect_to attack_defenders_path(@attack) }
      format.xml  { head :ok }
    end
  end
end
